-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/libusb #242
Feature/libusb #242
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #242 +/- ##
==========================================
- Coverage 62.86% 62.8% -0.07%
==========================================
Files 49 49
Lines 1570 1570
Branches 216 217 +1
==========================================
- Hits 987 986 -1
- Misses 518 519 +1
Partials 65 65
Continue to review full report at Codecov.
|
// val ret = nativeClaimInterface(libUsbHandle, usbInterface.id) | ||
// if (ret < 0) { | ||
// throw IOException("libusb returned $ret in claim interface") | ||
// } | ||
val claim = deviceConnection!!.claimInterface(usbInterface, true) | ||
if (!claim) { | ||
throw IOException("could not claim interface!") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't libusb claim it? I'm worried this may cause issues because I've seen it internally does unclaim/claim in reset_device, for example.
Why exactly I have not figured out yet. But I got some device not connected error for the function call detaching the kernel driver and then a device busy error for claiming the usb device using libusb. But feel free to play around with that. The other thing is that some stuff just does not work (eg iterating the usb devices ) from libusb because of androids permission system.
… On 10. Jan 2020, at 21:31, Davide Depau ***@***.***> wrote:
@depau commented on this pull request.
In libusbcommunication/src/main/java/me/jahnen/libaums/libusbcommunication/LibusbCommunication.kt:
> +// val ret = nativeClaimInterface(libUsbHandle, usbInterface.id)
+// if (ret < 0) {
+// throw IOException("libusb returned $ret in claim interface")
+// }
+ val claim = deviceConnection!!.claimInterface(usbInterface, true)
+ if (!claim) {
+ throw IOException("could not claim interface!")
+ }
Why can't libusb claim it? I'm worried this may cause issues because I've seen it internally does unclaim/claim in reset_device, for example.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Yes, I figured listing devices wouldn't work, but I didn't expect the claiming process would require assistance from the system. I didn't get the chance to test :/ maybe within a few days |
I did not put too much time into that, so maybe we are still missing something to claim the interface using libusb. I guess one easy test would be to try claiming with a rooted device to see if it is really a permission problem. |
I think internally it tries to claim/unclaim sometimes but the code I have seen does usually ignore errors from claiming and just proceeds. |
// val ret = nativeClaimInterface(libUsbHandle, usbInterface.id) | ||
// if (ret < 0) { | ||
// throw IOException("libusb returned $ret in claim interface") | ||
// } | ||
val claim = deviceConnection!!.claimInterface(usbInterface, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@depau so this seems to work
I made some tests with a usb hub and two drives, which usually never worked. With libusb this works quite well, so I hope that you will come to the same conclusion :) |
} | ||
} | ||
|
||
interface UsbCommunicationCreator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
/** | ||
* Created by magnusja on 21/12/16. | ||
*/ | ||
|
||
object UsbCommunicationFactory { | ||
class NoUsbCommunicationFound : IOException() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private external fun nativeClose(handle: Long, interfaceNumber: Int) | ||
private external fun nativeReset(handle: Long) | ||
private external fun nativeClearHalt(handle: Long, interfaceNumber: Int) | ||
private external fun nativeBulkTransfer(handle: Long, endpointAddress: Int, data: ByteArray, offset: Int, length: Int, timeout: Int): Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import java.nio.ByteBuffer | ||
import kotlin.math.absoluteValue | ||
|
||
class LibusbCommunication( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
class LibusbCommunicationCreator : UsbCommunicationCreator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private external fun nativeReset(handle: Long) | ||
private external fun nativeClearHalt(handle: Long, interfaceNumber: Int) | ||
private external fun nativeBulkTransfer(handle: Long, endpointAddress: Int, data: ByteArray, offset: Int, length: Int, timeout: Int): Int | ||
private external fun nativeControlTransfer(handle: Long, requestType: Int, request: Int, value: Int, index: Int, buffer: ByteArray, length: Int, timeout: Int): Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import java.nio.ByteBuffer | ||
import kotlin.math.absoluteValue | ||
|
||
class LibusbCommunication( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
} | ||
|
||
interface UsbCommunicationCreator { | ||
fun create(usbManager: UsbManager, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm testing it and it's doing great! I'll see how it does on QEMU if my tiny RAM allows it |
I tested it on my two phones and on QEMU with a real USB drive passed through, it's working much better than the Android API implementation. Still not working on QEMU with an emulated drive, it times out: https://pastebin.com/iGxQCz0k I'm still not aware of what's wrong with it, it works fine if I pass-through a real USB drive, the emulated one works with Linux but not in userspace. |
Hey @depau thanks a lot for testing! Awesome, that is good news. Then I will merge this and prepare a release so that other people can test this as well. Regarding QEMU: Well that is unfortunate. If the emulated drive does not work in userspace in Linux the same problem might be in Android then as well. Can you maybe provide me with information on running QEMU, so that I can play around with this as well? |
No description provided.